module OrigenTesters
  module SmartestBasedTester
    class V93K_SMT8
      # Include this module in an interface class to make it a V93K interface and to give
      # access to the V93K SMT8 program generator API
      module Generator
        extend ActiveSupport::Concern

        require_all "#{Origen.root!}/lib/origen_testers/smartest_based_tester/v93k_smt8"
        require 'origen_testers/smartest_based_tester/base/generator'

        included do
          include Base::Generator
          PLATFORM = V93K_SMT8
        end

        # Sub flows are generated in a forked process for SMT8, however any updates made to interface
        # instance variables by the sub-flow will be applied to the interface of the master process.
        # This is what the user would expect to happen and keeps them largely unaware of the fact that
        # the sub-flow is actually being generated by a forked process.
        # However, to do this it is necessary to marshal the value of the instance variables and
        # some (rich) Ruby objects cannot be marshaled. This parameter allows applications to selectively
        # mark such variables as not to be returned from the forked process, skipping the marshal
        # operation but also meaning that any changes made to the variable by the sub-flow will not
        # be visible to the top-level flow.
        #
        # If the application actually needs updates to that variable made during a sub-flow to
        # be available to the top-level flow, then they will need to work around it in another
        # way on a case by case basis.
        #
        #   # In the application's interface
        #   sub_flow_no_return_vars << :@my_problem_var
        def sub_flow_no_return_vars
          @sub_flow_no_return_vars ||= []
        end

        # See sub_flow_no_return_vars
        def sub_flow_no_return_vars=(val)
          @sub_flow_no_return_vars = val
        end

        def limits_workbook
          @@limits_workbook ||= LimitsWorkbook.new(manually_register: true)
        end
      end
    end
  end
end
